<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="./css/xadmin.css">
<style>
form {
	padding: 60px;
}

form p {
	display: flex;
	flex-direction: column;
	justify-content: center;
}

form label {
	font-size: 16px;
	margin-bottom: 30px;
}

#mynew {
	width: 200px;
}

form button {
	margin-top: 30px;
}
</style>
</head>
<body>
	<form action="#" onsubmit="return check()">
		<input type="hidden" id="idbox" value="${id } " />
		<p>
			<label for="mynew">类别: </label> <input id="mynew" name="newclass"
				type="text" class="layui-input" value="${name }" />
		</p>
		<button class="layui-btn" type="submit">保存</button>
	</form>

	<script type="text/javascript" src="./js/jquery.min.js"></script>
	<script>
		function check() {
			let id = $("#idbox").val();
			let name = $("#mynew").val();
			if(name==""){
				alert("类别不能为空！");
				return;
			} 

			$.post("${ pageContext.request.contextPath }/admin/saveprodclass",
					{
						"id" : id,
						"name" : name
					}, function(res) {
						//-1 已存在   0 失败  1成功
						if(res.code==-1){
							alert("该分类名已存在!");
							
						}else if(res.code==0){
							alert("数据库错误，请稍后再试!")
						}else if(res.code==1){
							alert("成功");
							// 获得frame索引
	                        var index = parent.layer.getFrameIndex(window.name);
	                        //关闭当前frame
	                        parent.location.reload();
	                        parent.layer.close(index);
						}
					},"json");

			return false;
		}
	</script>

</body>
</html>